# -*- coding:UTF-8 -*-
from bs4 import BeautifulSoup
import requests
class UrlManager(object):
    def __init__(self):
        self.new_urls=[]
        self.old_urls=[]
        self.new=[]
        self.old=[]
    def add_new_url(self, url):#单个添加,每个以列表形式添加["url",0]
        if url is None:
            return
        for i in range(0,len(self.new_urls)):
            self.new.append(self.new_urls[i][0])
        if len(self.old_urls)!=0:
            for j in range(0,len(self.old_urls)):
                self.old.append(self.old_urls[j][0])
        if url[0] not in self.new and url[0] not in self.old:
            self.new_urls.append(url)
            self.new.append(url[0])
    def add_new_urls(self, urls):#添加一个列表[["url",1],["url",1]]
        if urls is None or len(urls) == 0:
            return
        for url in urls:
            self.add_new_url(url)
            
    def get_new_url(self):# pop方法会获取一个url并且移除它
        new_url = self.new_urls.pop()
        self.old_urls.append(new_url)
        a=self.new_urls.pop()
        self.old_urls.append(a)
        print(new_url)
        return new_url 
        
    def has_new_url(self):#判断是否还有链接
        return len(self.new_urls) != 0
    
